package com.yicun.road.service.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yicun.road.service.pojo.api.CommonResult;
import com.yicun.road.service.pojo.base.ResultCode;
import com.yicun.road.service.pojo.base.RspPageInfo;
import com.yicun.road.service.pojo.disease.TShapes;
import com.yicun.road.service.service.TShapesService;
import com.yicun.road.service.util.ResponseUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author liushan
 * @since 2022-06-14
 */
@RestController
@RequestMapping("/shapes")
public class TShapesController {

    @Resource
    private TShapesService tShapesService;

    /**
     * 目标信息列表
     *
     * @param tShapes
     * @return
     */
    @PostMapping("/queryTPointsList")
    @ApiOperation(value = "查询目标信息列表(带分页)")
    public RspPageInfo<List<TShapes>> queryTShapesList(@RequestBody TShapes tShapes) {
        try {
            Page<TShapes> page = tShapesService.queryTShapesList(tShapes);
            return ResponseUtil.makePageRsp(ResultCode.SUCCESS.CODE, page.getTotal(), "", page.getRecords());
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseUtil.makePageRsp(ResultCode.FAIL.CODE, 0, "系统异常:" + e.getMessage(), null);
        }
    }

    /**
     * 新增目标信息列表
     *
     * @param tShapes
     * @return
     */
    @PostMapping("/sava")
    @ApiOperation(value = "新增")
    public CommonResult saveTShapes(@RequestBody TShapes tShapes) {
        return CommonResult.success(tShapesService.saveTShapes(tShapes));
    }

    /**
     * 修改目标信息列表
     *
     * @param tShapes
     * @return
     */
    @PutMapping("/update")
    @ApiOperation(value = "修改")
    public CommonResult updateTShapes(@RequestBody TShapes tShapes) {
        tShapesService.updateTShapes(tShapes);
        return CommonResult.success();
    }

    /**
     * 删除目标信息列表
     *
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    @ApiOperation(value = "删除")
    public CommonResult deleteTShapes(@PathVariable Integer id) {
        tShapesService.deleteTShapes(id);
        return CommonResult.success("删除成功！");
    }
}

